<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:p="http://primefaces.org/ui" >

	<h:form id="frm2">	
		<p:growl id="msgs2" showDetail="true" />
		<p:panel id="prodPanel" header="【第二步】产品信息录入" style="margin-bottom:5px" toggleable="true" >
	
 			<h:panelGrid columns="4" cellspacing="10">		
 			   	<p:outputLabel id="pcontractid" value="当前合同编号: #{contractMB.io.id}" style="color:blue;"/>	
                 	
				<p:commandButton id="prodBtn" value="选择合同产品..." type="button" icon="fa fa-fw fa-search-plus" onclick="PF('ovpl').loadContents();" />		

				<p:commandButton value="生成合同金额" icon="ui-icon-plus" 
	           		process="@this" update=":frm1:pContractPrice :frm1:msgs1"
                 	actionListener="#{contractMB.genContractPrice}" >					
				</p:commandButton>
			</h:panelGrid>
			
			<p:dataTable id="rdt" value="#{contractMB.vop}"  var="row"  rowIndexVar="rowNum"
				resizableColumns="true" liveResize="true" 
				editable="true"  style="margin-bottom:5px"
				paginator="true" paginatorPosition="bottom" rows="8" 
                rowsPerPageTemplate="5,10,15"  emptyMessage="没有记录" >
				
				<f:facet name="header">
			        合同产品信息
			    </f:facet>
    
				<p:ajax event="rowEdit" listener="#{contractMB.onRowEdit}"
					update=":frm2:msgs2 :frm2:rdt" />
				<p:ajax event="rowEditCancel"	listener="#{contractMB.onRowCancel}"
					update=":frm2:msgs2" />
				<p:column headerText="No." style="width:5%">
					#{rowNum+1}
				</p:column>
				<p:column headerText="物料编号" sortBy="#{row.bmeMaterial.id}">
					<h:outputText value="#{row.bmeMaterial.id}" />
				</p:column>
				<p:column headerText="物料描述">
					<h:outputText value="#{row.bmeMaterial.mdesc}" />
				</p:column>
				<p:column headerText="规格">
					<h:outputText value="#{row.bmeMaterial.mmodel}" />
				</p:column>
				<p:column headerText="数量">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{row.quantity}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText value="#{row.quantity}" style="width:100%" />
						</f:facet>
					</p:cellEditor>
				</p:column>

				<p:column headerText="单价">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{row.price}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText value="#{row.price}" style="width:100%" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="金额">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{row.amount}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText id="aaaa" value="#{row.amount}" style="width:100%"
								label="金额" />
						</f:facet>
					</p:cellEditor>
				</p:column>

				<p:column headerText="加工规格">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{row.speci}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText value="#{row.speci}" style="width:100%" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="数量-片">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{row.processQuantity}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText value="#{row.processQuantity}" style="width:100%" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="加工工艺">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{row.processTeck}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText value="#{row.processTeck}" style="width:100%" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="安装区域">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{row.area}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText value="#{row.area}" style="width:100%"
								label="安装区域" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="备注">
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{row.remarks}" />
						</f:facet>
						<f:facet name="input">
							<p:inputText value="#{row.remarks}" style="width:100%"
								label="备注" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="修改" style="width:32px">
					<p:rowEditor editTitle="修改" cancelTitle="取消" saveTitle="保存"/>
				</p:column>
				<p:column headerText="删除" style="width:32px">
					<p:commandButton icon="ui-icon-minus"   title="删除"  immediate="true"
						action="#{contractMB.delProduct}" update=":frm2">
						<f:setPropertyActionListener value="#{row}"
							target="#{contractMB.selectedp}" />
						<p:confirm header="确认" message="你确定删除此产品信息？" icon="ui-icon-alert" />
					</p:commandButton>	
				</p:column>
				
			</p:dataTable>
    
		</p:panel>

    	<p:overlayPanel id="prodBtnPanel" for="prodBtn" hideEffect="fade" dynamic="true" 
   				showCloseIcon="false" style="width:600"  widgetVar="ovpl"  >
	        <p:dataTable var="srow" value="#{contractMB.bmeMaterials}"  
	        	paginator="true" paginatorPosition="bottom" rows="8"
	         	selection="#{contractMB.selectedMaterials}" rowKey="#{srow.id}"
	         	style="margin-bottom:0"	>
	         	
	           <p:column selectionMode="multiple" style="width:16px;text-align:center"/>
	           <p:column headerText="物料编号" filterBy="#{srow.id}" filterMatchMode="contains" >
	               <h:outputText value="#{srow.id}" />
	           </p:column>
	           <p:column headerText="物料描述" filterBy="#{srow.mdesc}" filterMatchMode="contains" >
	               <h:outputText value="#{srow.mdesc}" />
	           </p:column>
	           <p:column headerText="规格" >
	               <h:outputText value="#{srow.mmodel}" />
	           </p:column>
	           <p:column headerText="销售单价">
	               <h:outputText value="#{srow.salePrice}" />
	           </p:column>
	       </p:dataTable>
	        <h:panelGrid columns="3" cellspacing="10">					  
				<p:commandButton value="确认"	icon="ui-icon-check"  oncomplete="PF('ovpl').hide();" 
					action="#{contractMB.saveProduct}"  update=":frm2" >
				</p:commandButton>	
			</h:panelGrid>   				
		
		 </p:overlayPanel>

		
	</h:form>
	<!-- confirm to del product -->
    <p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
        <p:commandButton value="确认" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
        <p:commandButton value="取消" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
    </p:confirmDialog>				
</ui:composition>
